﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pipes.Queries.Model.Query
{
  public class LogicalNot : IExpression
  {
    public bool Deterministic { get { return true; } }
    public MetaData.GeneralDataType InferredType { get; set; }
    public IExpression Operand { get; set; }

    public LogicalNot() 
    {
      this.InferredType = MetaData.GeneralDataType.boolean;
    }
    public LogicalNot(IExpression operand) : this()
    {
      this.Operand = operand;
    }

    public void Visit(Parser.IQueryVisitor visitor)
    {
      visitor.Visit(this);
    }

    public object Evaluate()
    {
      bool result = false;
      if (Execution.ExecUtils.TryGetBool(this.Operand.Evaluate(), out result))
      {
        return !result;
      }
      else
      {
        return DBNull.Value;
      }
    }
  }
}
